/*
 *  $Id: Gluttony.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2009 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Cards001.Air.Spells {
    public class Gluttony: SelfEnchantmentCard {
        public Gluttony(): base("001_a_s_gluttony") {
            Level = CompleteLevel.ReadyForTest;
            Version = 0;
            Element = ElementType.Air;
            Value = 100;
            AddManaCost(ElementType.Air, 2);
        }

        protected override EnchantmentAffect CreateEnchantment() {
            return new GluttonyAffect();
        }

        private class GluttonyAffect: EnchantmentAffect<Gluttony> {
            public override void SetAffect() {
                base.SetAffect();
                GlobalSummary.OnStartDefencePhase += DoOwnerDefence;
                EnemySummary.OnStartDefencePhase += DoEnemyDefence;
            }
            public override void ResetAffect() {
                base.ResetAffect();
                GlobalSummary.OnStartDefencePhase -= DoOwnerDefence;
                EnemySummary.OnStartDefencePhase -= DoEnemyDefence;
            }

            private void DoOwnerDefence() {
                DoDefence(Owner.Owner);
            }
            private void DoEnemyDefence() {
                DoDefence(Owner.Owner.Enemy);
            }
            private void DoDefence(Player owner) {
                int count = 0;
                foreach (Creature cr in owner.GetCreatures())
                    if (!cr.Disabled)
                        count++;
                int cards = Math.Min(count, owner.Hands.Count);
                if (cards > 0) {
                    owner.ReleaseCards(cards);
                    count -= cards;
                }
                if (count > 0)
                    owner.DamageDirectBy(NewDamage(DamageType.Health, count), true);
            }
        }
    }
}
